package tk.mybatis.web.controller;

import java.util.*;
import java.util.concurrent.Callable;

import org.springframework.http.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.RedirectView;

import tk.mybatis.web.model.*;

//不同类型的参数与返回值测试
@Controller
@RequestMapping("myTest2")
public class MyTest2 {

	@RequestMapping(value = "a", method = RequestMethod.GET)
	public ModelAndView a() {
		ModelAndView mv = new ModelAndView("myTest2/a");
		mv.addObject("model",new MyTestModel("DefaultText"));
		return mv;
	}

	// 接收实体原样返回
	@RequestMapping(value = "a", method = RequestMethod.POST)
	public ModelAndView a(MyTestModel model) {
		ModelAndView mv = new ModelAndView("myTest2/a");
		mv.addObject("model", model);
		return mv;
	}

	@RequestMapping(value = "b", method = RequestMethod.GET)
	public ModelAndView b() {
		ModelAndView mv = new ModelAndView();
		return mv;
	}

	// 接收Map原样返回
	@RequestMapping(value = "b", method = RequestMethod.POST)
	public ModelAndView b(@RequestParam HashMap<String, String> map) {
		ModelAndView mv = new ModelAndView();
		mv.addObject("map", map);
		return mv;
	}
	// 返回HttpEntity
	@RequestMapping(value = "c", method = RequestMethod.GET)
	public HttpEntity<MyTestModel> c() {
		return new ResponseEntity<MyTestModel>(new MyTestModel("返回HttpEntity"), HttpStatus.OK);
	}
	// 返回MyTestModel
	@RequestMapping(value = "c1", method = RequestMethod.GET)
	@ResponseBody
	public MyTestModel c1() {
		return new MyTestModel("返回实体");
	}
	// 返回HttpEntity
	@RequestMapping(value = "c3", method = RequestMethod.GET)
	public HttpEntity<String> c3() {
		return new HttpEntity<String>("返回String");
	}
	// 返回Model
	@RequestMapping(value = "d", method = RequestMethod.GET)
	public Model d() {
		return new ExtendedModelMap().addAttribute("Key", "ExtendedModelMap Value");
	}
	// 返回Callable，由于配置问题执行报错
	@RequestMapping(value = "e", method = RequestMethod.GET)
	public Callable<String> e() {
		return () -> "Callable Result";
	}

	// 返回DeferredResult，由于配置问题执行报错
	@RequestMapping(value = "f", method = RequestMethod.GET)
	public DeferredResult<String> f() {
		return new DeferredResult<String>(5000L, "DeferredResult Result");
	}

	// 重定向
	@RequestMapping(value = "g", method = RequestMethod.GET)
	public View g() {
		return new RedirectView("d");
	}
}
